package com.zhaogang.Timer;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.zhaogang.entity.Order;
import com.zhaogang.service.OrderService;
@Component
public class OrderTimer {
	
	@Autowired
	private OrderService orderService;
	
	@Scheduled(cron="0/5 * * * * ? ")
	public void payOrder() {
		List<Order> os = orderService.selectAllNoEndOrder();
		System.out.println(os);
		if(!(os == null)){
			for (Order order : os) {
				

				if((new Date().getTime() - order.getOrderTime().getTime()) > 1000*30){
					System.out.println(new Date().getTime() - order.getOrderTime().getTime());
					boolean b = orderService.delOrderTimer(order.getId(),order.getNum(),order.getSaleGoodsId());
					if(b){
						System.out.println("未完成订单"+order.getId()+"以删除");
					}
				}
			}
		}
		
	}
}
